package com.gao.sentinel.common.id;

import com.gao.sentinel.common.Constants;
import com.gao.sentinel.common.id.impl.RandomNumeric;
import com.gao.sentinel.common.id.impl.SnowFlake;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@Configuration
public class IdContext {

    /**
     * Id 策略模式上下文配置
     * @param snowFlake         雪花算法，长码，大量
     * @param randomNumeric     随机算法，短码，大量，全局唯一需要自己保证
     * @return
     */
    @Bean
    public Map<Constants.Ids, IdGenerator> idGenerator(SnowFlake snowFlake, RandomNumeric randomNumeric) {
        Map<Constants.Ids, IdGenerator> idGeneratorMap = new HashMap<>(8);
        idGeneratorMap.put(Constants.Ids.SnowFlake, snowFlake);
        idGeneratorMap.put(Constants.Ids.RandomNumeric, randomNumeric);

        return idGeneratorMap;
    }
}
